local skel = fk.CreateSkill {
  name = "emo__caishuang",
}

Fk:loadTranslationTable{
  ["emo__caishuang"] = "裁霜",
  [":emo__caishuang"] = "结束阶段，你可以选择一名手牌数大于你的角色，每名手牌数小于其的角色依次视为对其使用一张冰【杀】，然后其视为对这些角色中手牌数不小于其的使用一张火【杀】。",

  ["#emo__caishuang-choose"] = "裁霜:选择手牌数大于你的角色，令手牌小于其的角色对其使用冰【杀】",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and player.phase == Player.Finish then
      return table.find(player.room.alive_players, function (p)
        return p:getHandcardNum() > player:getHandcardNum()
      end) ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p)
      return p:getHandcardNum() > player:getHandcardNum()
    end)
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = targets, skill_name = skel.name,
      prompt = "#emo__caishuang-choose",
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1] ---@type ServerPlayer
    local targets = table.filter(room:getAlivePlayers(), function (p)
      return p:getHandcardNum() < to:getHandcardNum()
    end)
    for _, p in ipairs(targets) do
      if to.dead then return end
      if not p.dead then
        room:useVirtualCard("ice__slash", nil, p, to, skel.name, true)
      end
    end
    local slash = Fk:cloneCard("fire__slash")
    slash.skillName = skel.name
    if to.dead or to:prohibitUse(slash) then return end
    targets = table.filter(targets, function (p)
      return not to:isProhibited(p, slash) and p:getHandcardNum() >= to:getHandcardNum() and not to.dead
    end)
    if #targets > 0 then
      room:useCard{from = to, tos = targets, card = slash, extraUse = true}
    end
  end,
})

return skel
